/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.display.miniboard;

import deatax.display.Texture;
import javax.media.opengl.GL2;

/**
 *
 * @author Caroline
 */
public class CardStackRenderer extends MiniBoardTile {

    public static float STACK_HEIGHT = 1.5f;
    
    public CardStackRenderer(int x, int y, String type,MiniBoard miniboard) {
        super(x, y, type,miniboard);
        if("Death".equals(type)){
            back = DEATH_TEXTURE;
        } else {
            back = TAX_TEXTURE;
        }
        texture = null;
        this.height = 1.5f;
    }
    
    private static Texture SIDE_TEXTURE = new Texture("card/side.png");
    private static Texture DEATH_TEXTURE = new Texture("card/death-back.png");
    private static Texture TAX_TEXTURE = new Texture("card/tax-back.png");
    
    private Texture back;
    
    public static float[] vertices = new float[]{
        -1,1,
        1,1,
        1,-1,
        -1,-1
    };
    
    public static float CARD_WIDTH = 2;
    public static float CARD_HEIGHT = 3;

    @Override
    public void draw(GL2 gl){
        super.draw(gl);
        
        gl.glColor3f(1,1,1);
        gl.glDisable(GL2.GL_CULL_FACE);
        gl.glEnable(GL2.GL_TEXTURE_2D);
        SIDE_TEXTURE.bind(gl);
        gl.glBegin(GL2.GL_TRIANGLE_STRIP);
        for(int i = 0; i < 10; i+=2){
            gl.glTexCoord2f((i%4)/2,0);
            gl.glVertex3f(vertices[i%8]*CARD_WIDTH, vertices[i%8+1]*CARD_HEIGHT,height+TILE_BEVEL);
            gl.glTexCoord2f((i%4)/2, 4);
            gl.glVertex3f(vertices[i%8]*CARD_WIDTH, vertices[i%8+1]*CARD_HEIGHT,height+TILE_BEVEL+STACK_HEIGHT);
        }
        gl.glEnd();
        back.bind(gl);
        gl.glBegin(GL2.GL_TRIANGLE_FAN);
        for(int i = 0; i < 8; i+=2){
            gl.glTexCoord2f((vertices[i]+1)/2,-(vertices[i+1]+1)/2);
            gl.glVertex3f(vertices[i]*CARD_WIDTH, vertices[i+1]*CARD_HEIGHT,height+TILE_BEVEL+STACK_HEIGHT);
        }
        gl.glEnd();
        
        gl.glDisable(GL2.GL_TEXTURE_2D);
        gl.glEnable(GL2.GL_CULL_FACE);
    }
    
}
